# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

root=TreeNode(1)
root.left=TreeNode(2)
root.left.left=TreeNode(3)
root.left.right=TreeNode(4)
root.right=TreeNode(5)
root.right.right=TreeNode(6)

def dfs(root,path):
    if root.right==None and root.left==None:
        path.append(root)
        return None
    #把当前结点放入path中
    path.append(root)
    #遍历左子树
    dfs(root.left,path)
    #遍历右子树
    dfs(root.right,path)

def flatten(root):
    """
    Do not return anything, modify root in-place instead.
    """
    if root:
        #不为空树的情况
        path=[]
        dfs(root,path)
        pathLen=len(path)
        if pathLen>1:
            process=root
            for i in range(1,pathLen):
                process.left=None
                process.right=path[i]
                process=process.right





